package mylab.commons.web.global;


import cn.hutool.core.util.StrUtil;
import mylab.base.model.dto.Result;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;

/**
 * 统一异常处理
 */
@ControllerAdvice
public class ExceptionHandlers {
    /**
     * 异常统一处理
     */
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    @ExceptionHandler(RuntimeException.class)
    public Result<?> runtimeException(RuntimeException e) {
        return Result.newFaild(StrUtil.format("发生运行时异常:\n{}", e.getMessage()));
    }
}
